<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>出库查询</title>
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script>
        $(function () {
            $("#tab").bootstrapTable({
                method: "post",
                contentType: "application/json",
                url: "/spay/querySpayAll",
                striped: true,
                pageNumber: 1,
                pagination: true,
                sidePagination: 'server',
                pageSize: 5,
                pageList: [3, 5, 6, 10],
                queryParams: function (params) {
                    return {
                        // 计算页号(当前页)
                        pageNumber: (params.offset / params.limit) + 1,
                        // 计算页大小
                        pageSize: params.limit,
                        querySearch:{
                            id:$("pay_id").val(),
                        }
                    }
                },
                columns: [
                    {title: '出库单编号', field: 'payId', align: 'center',formatter(value, row, index) {
                        return "<a  style='text-decoration:underline' data-toggle='modal' data-target='#myModal2' onclick='Registration("+JSON.stringify(row)+")'>"+value+"</a>"

                        }
                    },
                    {title: '出库理由', field: 'reason', align: 'center', formatter: function (value, row, index) {
                            if (value == "c002-1") {
                                return "生产领料";
                            } else if (value == "c002-2") {
                                return "赠送";
                            } else if (value == "c002-3") {
                                return "内部借领";
                            } else if (value == "c002-4") {
                                return "其他借领"
                            } else {
                                return "其他";
                            }
                        }
                    },
                    {title: '出库详细理由',field: 'reasonexact',align: 'center'},
                    {title: '完成时间',field: 'registerTime',align: 'center'},
                    {title: '应出库总件数', field: 'amountSum', align: 'center'},
                    {title: '已出库总件数', field: 'gatheredAmountSum', align: 'center'},
                    {title: '出库单状态',field: 'storeTag',align: 'center',
                        formatter: function (value, row, index) {
                            if(value=='k002-1'){
                                return "<span class='btn btn-outline-warning'>等待</span>"
                            }else if(value=='k002-3'){
                                return "<span class='btn btn-outline-success'>执行</span>"
                            }else{
                                return "<span class='btn btn-outline-success'>完成</span>"
                            }
                        }
                    },
                ]
            })
        })
        function findAcc() {
            $.ajax({
                type: 'post',
                url: '/SysUser/queryUser',
                success: function (result) {
                    $("#register").val(result.loginId);
                }
            })
        }
        function findcost_price_sum(val) {
            $.ajax({
                type:'post',
                url:'/spay/querySpayTotalcost',
                data:'id='+val,
                success:function (result) {
                    $("#costPrice_Sum").val(result);
                }
            })
        }
        function Registration(data) {
            findAcc();
            findcost_price_sum(data.id);
            $(".gatherId").val(data.payId);
            var re='';
            if (data.reason == "r001-1") {
                re= "生产入库";
            } else if (data.reason == "r001-2") {
                re= "库存初始";
            } else if (data.reason == "r001-3") {
                re= "赠送";
            } else if (data.reason == "r001-4") {
                re= "内部归还"
            } else {
                re= "其他归还";
            }
            $("#reason").val(re);
            $("#amountSum").val(data.amountSum);
            $("#costPriceSum").val(data.costPriceSum);
            console.log(data.paidAmountSum);
            $("#amount_Sum").val(data.paidAmountSum);
            $("#register_time").val(new Date().toLocaleString());
            $("#table2").bootstrapTable("destroy");
            $("#table2").bootstrapTable({
                method: "get",
                contentType: "application/json;charset=utf-8",
                url: "/spay/findSpayDetailsById",
                queryParams: function (params) {
                    return {
                        id:data.id,
                    }
                },
                columns: [
                    {title: '产品编号', field: 'product_id', align: 'center',formatter:function (value,row,index) {
                            return "<span  class='productId'>"+value+"</span>"
                        }},
                    {title: '产品名称', field: 'product_name', align: 'center'},
                    {title: '库房名称', field: 'id',align: 'center',formatter:function (value,row,index) {
                            return "成品房"
                        }},

                    {title: '应出库件数', field: 'amount', align: 'center'},
                    {title: '已出库件数', field: 'paid_amount', align: 'center',formatter:function (value,row,index) {
                            if(value==null){
                                return 0;
                            }else{
                                return  value;
                            }
                        }},
                    {title: '应出库小计', field: 'subtotal', align: 'center'},
                    {
                        title: '已出库小计', field: 'quantity_in_storage', align: 'center',formatter: function (value, row, index) {
                            return  row.paid_amount*row.cost_price;

                        }

                    },
                    {title: '序列号',field: 'id',align: 'center',formatter:function (value,row,index) {
                            return "<span class='id'>"+value+"</span>"
                        }}
                ]
            })
        }

    </script>
</head>
<body>
<table id="tab">

</table>
<div class="modal fade" id="myModal2">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title" style="margin-left: 43%;">出库单</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">
                <div>
                    <div class="form-inline row" style="margin-left: 5%">
                        <span class="">&nbsp;&nbsp;&nbsp;出库单编号：</span>
                        <input type="text" readonly id="gatherId" class="form-control col-3 gatherId">
                        <div class="col-2"></div>
                        <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;出库理由：</span>
                        <input id="reason" readonly class="form-control col-3">
                        </input>
                    </div>

                </div>

                <table id="table2" class="table tab-content table-hover" style="margin-top: 20px;border: 1px black solid">

                </table>


                <div class="form-inline row" style="margin-top: 20px;margin-left: 5% ">
                    <span class="">应出库总件数：</span>
                    <input type="text" readonly id="amountSum" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">已出库总件数：</span>
                    <input type="text" value="0" readonly id="amount_Sum" class="form-control col-3">
                </div>
                <div class="form-inline row" style="margin-top: 20px ;margin-left: 5%">

                    <span class="">应出库总成本：</span>
                    <input type="text"   readonly id="costPriceSum" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">已出库总成本：</span>
                    <input id="costPrice_Sum" value="0" readonly type="text" class="form-control col-3">
                </div>
                <div class="form-inline row" style="margin-top: 20px;margin-left: 5% ">

                    <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登记人：</span>
                    <input type="text" readonly id="register" class="form-control col-3">
                    <div class="col-2"></div>
                    <span class="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登记时间：</span>
                    <input type="text" value="0" readonly id="register_time" class="form-control col-3">
                </div>

            </div>



            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>